/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.spec;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.core.common.dao.page.PagerModel;
import shop.services.front.spec.SpecService;
import shop.services.front.spec.bean.Spec;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**   
 * @类名称：SpecController
 * @创建人：Wzl
 * @创建时间：2017-09-20 下午15:51:23      
 * @版本号：1.0
 * @描述：商品规格
 */
@Controller
@RequestMapping("/front/spec/")
public class SpecController extends FrontBaseController<Spec> {
    @Resource
    private SpecService specService;
    @Override
    public Services<Spec> getService() {
        return specService;
    }

    /**
     * 查询规格列表
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectSpecList")
    @ResponseBody
    public JSONResult selectSpecList(Spec spec){
        List<Spec> specList = specService.selectSpecList(spec);
        JSONResult jsonResult = new JSONResult();
        jsonResult.setData(specList);
        return jsonResult;
    }

    /**
     * 查询规格数组
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectSpecArray")
    @ResponseBody
    public JSONResult selectSpecArray(Spec spec){
        List<Spec> specList = specService.selectSpecList(spec);
        String []specSize=new String[specList.size()];
        String []specTaste=new String[specList.size()];
        List<String>specSizeList=new ArrayList<>();
        List<String>specTasteList=new ArrayList<>();
        for(int i=0;i<specList.size();i++){
            String []combination=specList.get(i).getCombination().split(",");
            specSize[i]=combination[0];
            specTaste[i]=combination[1];
            if(!specSizeList.contains(specSize[i]))
                specSizeList.add(specSize[i]);
            if(!specTasteList.contains(specTaste[i]))
                specTasteList.add(specTaste[i]);
        }
        String []specSizeUnRepeat=new String[specSizeList.size()];
        String []specTasteUnRepeat=new String[specTasteList.size()];
        for(int i=0;i<specSizeList.size();i++){
            specSizeUnRepeat[i]=specSizeList.get(i);
        }
        for(int i=0;i<specTasteList.size();i++){
            specTasteUnRepeat[i]=specTasteList.get(i);
        }
        spec.setSpecSize(specSizeUnRepeat);
        spec.setSpecTaste(specTasteUnRepeat);
        JSONResult jsonResult = new JSONResult();
        jsonResult.setData(spec);
        return jsonResult;
    }

    @Override
    public JSONResult insertJson(HttpServletRequest request, Spec spec) throws Exception {
        return null;
    }

    @Override
    public JSONResult deleteJson(HttpServletRequest request, Spec spec) throws Exception {
        return null;
    }
}
